<?php
/**
 * @version		1.0.0
 * @category	Anahita Social Simple Blogs
 * @copyright	Copyright (C) 2008 - 2010 rmdStudio Inc. and Peerglobe Technology Inc. All rights reserved.
 * @license		GNU GPLv3 <http://www.gnu.org/licenses/gpl-3.0.html>
 * @link     	http://www.anahitapolis.com
 */

/**
 * Add Post Actions
 * 
 * 
 */
class ComSblogsViewPostAction extends AnSekitAction
{	
	
	/**
	 * Add Actions to the context
	 * 
	 * @param KViewTemplate
	 * @param AnCsArray $actions
	 * @return void
	 */
	public function listActions($view, $actions, $data)
	{
		
	}	
	
	/**
	 * Add Actions to the context
	 * 
	 * @param KViewTemplate
	 * @param AnCsArray $actions
	 * @return void
	 */
	public function postActions($view, $actions, $data)
	{	
		$post = $view->post;
		
		if ( $post->getAcl()->allowSubscribe() )
		{
			if ( $sub = $post->subscriptions->fetch($view->viewer) )
			{
				$url = $post->getURL().'&action=delete_subscription&sid='.$sub->id;			
				$actions['subscription'] = $this->link( JText::_('AN-SE-ACTION-UNSUBSCRIBE'), 
								JRoute::_($url))
								->action('post');
			}
			else
			{
				$url = $post->getURL().'&action=add_subscription';
				$actions['subscription'] = $this->link( JText::_('AN-SE-ACTION-SUBSCRIBE'), 
								JRoute::_($url))
								->action('post');
			}
		}
		
		if ( $post->getAcl()->allowUpdate() )
		{
			$actions['edit'] = 	$this->link( JText::_('AN-SE-ACTION-EDIT'), 'index.php?option=com_sblogs&view=post&layout=edit&id='.$post->id );
		}
			
		if( $post->owner->getAcl()->allowAdministration() )
		{
			$actions['delete'] = $this->link( JText::_('AN-SE-ACTION-DELETE'), 
								'index.php?option=com_sblogs&view=post&action=delete&id='.$post->id)
								->action('post');
		
				
			
			$comment_status_task_title = $post->openToComment ? JTEXT::_('AN-SE-ACTION-CLOSE-COMMENTING') : JTEXT::_('AN-SE-ACTION-OPEN-COMMENTING');
		
			$actions['comment'] = $this->link( $comment_status_task_title, 
									$this->_makeURL($url, array('openToComment'=>$post->openToComment ? 0 : 1))
									)
									->action('post')
									->class('an-discus-topic-action-status')->topic_id($post->id);	

		}								
	}
	
	
	/**
	 * Return a URL by adding the parts as a query
	 * 
	 * @param string $url
	 * @param array $parts
	 * @return string
	 */
	protected function _makeURL($url, $parts)
	{
		foreach($parts as $key => $value)
		{
			$url .= '&property['.$key.']='.$value;
		}
		
		return $url;	
	}	

//end class	
}